home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * *
- * Copyright (c) 1991 Silicon Graphics, Inc. *
- * All Rights Reserved *
- * *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
- * *
- * The copyright notice above does not evidence any actual of intended *
- * publication of such source code, and is an unpublished work by Silicon *
- * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
- * the property of Silicon Graphics, Inc. Any use, duplication or *
- * disclosure not specifically authorized by Silicon Graphics is strictly *
- * prohibited. *
- * *
- * RESTRICTED RIGHTS LEGEND: *
- * *
- * Use, duplication or disclosure by the Government is subject to *
- * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
- * Technical Data and Computer Software clause at DFARS 52.227-7013, *
- * and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
- * Supplement. Unpublished - rights reserved under the Copyright Laws of *
- * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
- * Shoreline Blvd., Mountain View, CA 94039-7311 *
- **************************************************************************
- *
- * File: state.c
- *
- * Description: Sets or gets the state of the spooling system for the
- * specified printer.
- *
- **************************************************************************/
-
-
- #ident "$Revision: 1.1 $"
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #ifdef sgi
- #include <getopt.h>
- #endif
- #include "spool.h"
-
-
- #define GET_OP 1
- #define SET_OP 0
-
-
- char *printer;
- int spooler = SL_SPOOLER_NONE;
-
-
- extern char *optarg;
- extern int optind;
-
-
- void usage(char*);
-
-
- main(int argc, char *argv[])
- {
- int ch, operation;
- int errflag = 0;
- int function, state, old_state, new_state;
- char *funcname;
-
- /*
- * Process command line args
- */
- while ((ch = getopt(argc, argv, "d:s:")) != -1) {
- switch(ch) {
- case 'd': /* Destination printer */
- printer = optarg;
- break;
- case 's': /* Spooler to use */
- if (!strcmp(optarg, "bsd"))
- spooler = SL_SPOOLER_BSD;
- else if (!strcmp(optarg, "sysv"))
- spooler = SL_SPOOLER_SYSV;
- else
- errflag++;
- break;
- case '?':
- default:
- errflag++;
- break;
- }
- }
-
- /*
- * Get the function - printing state or queueing state
- */
- if (argc == optind)
- errflag++;
- else {
- funcname = argv[optind];
- if (!strcmp(argv[optind], "printing"))
- function = SL_PRINTING;
- else if (!strcmp(argv[optind], "queueing"))
- function = SL_QUEUEING;
- else
- errflag++;
- }
-
- /*
- * Get the state, if any. If a state is specified this is
- * a set operation. If no state is specified, this is a
- * get operation.
- */
- if (!errflag) {
- optind++;
- if (argc == optind) {
- operation = GET_OP;
- } else {
- operation = SET_OP;
- if (!strcmp(argv[optind], "enable"))
- state = SL_ENABLED;
- else if (!strcmp(argv[optind], "disable"))
- state = SL_DISABLED;
- else
- errflag++;
- }
- }
-
- /*
- * If error print usage and exit
- */
- if (errflag) {
- usage(argv[0]);
- exit(1);
- }
-
- /*
- * If a spooling system has been specified set it
- */
- if (spooler != SL_SPOOLER_NONE) {
- if (SLSetSpooler(spooler) < 0) {
- SLPerror(argv[0]);
- exit(1);
- }
- }
-
- if (operation == SET_OP) {
- /*
- * Get the old state
- */
- if (SLGetSpoolerState(printer, function, &old_state) < 0) {
- int i, status, nout;
- char **out_buf;
- SLPerror(argv[0]);
- if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
- (void)fprintf(stderr, "Spooler exit status: %d\n", status);
- (void)fprintf(stderr, "Spooler error message(s):\n");
- for (i = 0; i < nout; i++)
- (void)fprintf(stderr, "\t%s\n", out_buf[i]);
- }
- exit(1);
- }
-
- /*
- * Set the new state
- */
- if (SLSetSpoolerState(printer, function, state) < 0) {
- int i, status, nout;
- char **out_buf;
- SLPerror(argv[0]);
- if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
- (void)fprintf(stderr, "Spooler exit status: %d\n", status);
- (void)fprintf(stderr, "Spooler error message(s):\n");
- for (i = 0; i < nout; i++)
- (void)fprintf(stderr, "\t%s\n", out_buf[i]);
- }
- exit(1);
- }
- }
-
- /*
- * Get the new state
- */
- if (SLGetSpoolerState(printer, function, &new_state) < 0) {
- int i, status, nout;
- char **out_buf;
- SLPerror(argv[0]);
- if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
- (void)fprintf(stderr, "Spooler exit status: %d\n", status);
- (void)fprintf(stderr, "Spooler error message(s):\n");
- for (i = 0; i < nout; i++)
- (void)fprintf(stderr, "\t%s\n", out_buf[i]);
- }
- exit(1);
- }
-
- /*
- * Print the results
- */
- (void)printf("Printer: %s\n", (printer) ? printer: "default");
- if (operation == SET_OP) {
- (void)printf("Original state of %s: %s\n", funcname,
- (old_state == SL_ENABLED) ? "enabled": "disabled");
- }
- (void)printf("Current state of %s: %s\n", funcname,
- (new_state == SL_ENABLED) ? "enabled": "disabled");
-
- return 0;
- }
-
-
- void usage(char *progname)
- {
- (void)fprintf(stderr, "%s [-d printer] [-s bsd | sysv] ", progname);
- (void)fprintf(stderr, "printing | queueing [enable | disable]\n");
- }
-